<template>
	<view class="zone">
		<!-- 登录页面 -->
		<view class="content">
			<image class="topimg1" src="http://image.qxgm.site/tdz/img/login/word.png" mode="widthFix"></image>
			<view class="listBox">
				<view class="list">
					<image class="yez" src="http://image.qxgm.site/tdz/img/login/ye.png" mode="widthFix"></image>
					<view class="aua">
						<image src="http://image.qxgm.site/tdz/img/public/l1.png" mode="widthFix"></image>
						<text>登录</text>
						<image src="http://image.qxgm.site/tdz/img/public/l2.png" mode="widthFix"></image>
					</view>
					<view class="piece">
						<span>手机号</span>
						<input type="number" v-model="phone" placeholder-class="placeholder_class" placeholder="请输入手机号">
					</view>
					<view class="piece">
						<span>密码</span>
						<input type="password" placeholder-class="placeholder_class" v-model="password"
							placeholder="请输入密码">
					</view>
					<view class="flexbw">
						<text @click="register">注册账号</text>
						<text @click="forget">忘记密码</text>
					</view>
					<view class="loginbtn" @click="login">
						登录
					</view>
					<u-checkbox-group class="checkgroup">
						<u-checkbox v-model="checked" :size="25" :label-disabled="false" class="checkbox">
							<view class="exieyi">
								<span>我同意</span>
								<text class="yellow" @click.stop="xieyi">《用户协议》</text>
								<span>与</span>
								<text class="yellow" @click.stop="yinsi">《隐私政策》</text>
							</view>
						</u-checkbox>
					</u-checkbox-group>

				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: '',
				password: '',
				checked: true,
			}
		},
		methods: {
			register() {
				uni.navigateTo({
					url: '/pages/login/register'
				});
			},
			forget() {
				uni.navigateTo({
					url: '/pages/login/forget'
				});
			},
			xieyi() {
				uni.navigateTo({
					url: '/pages/login/agreement'
				})
			},
			yinsi() {
				uni.navigateTo({
					url: '/pages/login/privacy'
				});
			},
			async login() {
				if (this.phone == '' || this.phone == null) {
					this.$u.toast("请输入手机号")
				} else if (!/^1[3456789]\d{9}$/.test(this.phone)) {
					this.$u.toast("手机号有误");
				} else if (this.password == '' || this.password == null) {
					this.$u.toast("请输入密码")
				} else if (!this.checked) {
					this.$u.toast("请勾选并同意用户协议与隐私政策")
				} else {
					let res = await this.$http.index.login({
						mobile: this.phone,
						pwd: this.password
					})
					if (res.code == 1) {

						uni.setStorageSync('token', res.data.token)
						if (res.data.data.length == 0) {
							uni.setStorageSync('data', false)
						} else {
							uni.setStorageSync('data', true)
						}

						this.$u.toast(res.msg)
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/tabbar/home'
							});
						}, 1500);
					} else {
						this.$u.toast(res.msg)
					}
				}
			},
		}
	}
</script>

<style scoped lang="less">
	.zone {
		padding: 6vh 0px 0;
		min-height: 100vh;
		background-image: url('http://image.qxgm.site/tdz/img/login/bg.png');
		background-size: 100% auto;
	}


	.topimg1 {
		display: block;
		margin: 0 auto;
		width: 79%;
	}

	.aua {
		display: flex;
		align-items: center;
		justify-content: space-around;
		margin-bottom: 3vh;

		text {
			font-weight: normal;
			font-size: 20px;
			color: #333333;
			line-height: 20px;
		}

		image {
			width: 20%;
		}
	}

	.listBox {
		margin-top: 4vh;
		background: url(http://image.qxgm.site/tdz/img/login/mg-02.png) no-repeat;
		background-size: 100% 100%;
	}

	.list {
		position: relative;
		padding: 5vh 14%;
	}

	.yez {
		position: absolute;
		width: 50px;
		bottom: -20px;
		right: -10px;
	}

	.piece {
		padding: 15px;
		margin-bottom: 6px;
		background: #efefef;
		border-radius: 1px;
		display: flex;
		align-items: center;
		justify-content: space-between;

		span {
			display: block;
			min-width: 50px;
			font-size: 14px;
			font-weight: normal;
			color: #50433A;
			line-height: 14px;
		}
	}

	.placeholder_class {
		font-size: 14px;
		color: #a09c99;
	}

	input {
		flex-grow: 1;
		width: 50%;
		font-size: 14px;
		color: #333;
	}

	.flexbw {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 18px;
		font-size: 14px;
		font-weight: normal;
		text-decoration: underline;
		color: #663300;
		line-height: 14px;
	}

	.loginbtn {
		width: 158px;
		height: 47px;
		background: url('http://image.qxgm.site/tdz/img/login/btn.png') no-repeat;
		background-size: 100% 100%;
		text-align: center;
		font-size: 18px;
		font-weight: normal;
		color: #fffcca;
		line-height: 47px;
		text-shadow: 0 1px 1px #CB6500;
		margin: 25px auto 20px;

	}

	.exieyi {
		font-size: 12px;
		color: #333;
	}

	.checkgroup {
		display: flex;
		align-items: center;
		justify-content: center;
		text-align: center;
	}

	.checkbox {
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.yellow {
		color: #09C90D;
	}

	/deep/ .u-checkbox__icon-wrap {
		background: #0F1A29 !important;
		border: 1px solid #999 !important;
		border-radius: 50% !important;
	}

	/deep/ .u-checkbox__icon-wrap--checked .u-icon__icon {
		color: #fff !important;
	}
</style>